//
//  HttpsBaseRequestTool.m
//  ABSallRec
//
//  Created by 我演示 on 2019/10/31.
//  Copyright © 2019 Jerry-Fu. All rights reserved.
//

#import "HttpsBaseRequestTool.h"

@implementation HttpsBaseRequestTool
+(void )baseRequestWithUrl:(NSString *)urlString {
 
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes =  [NSSet setWithObjects:@"text/html",@"text/xml",@"text/json",@"text/plain",@"text/JavaScript",@"application/json",@"image/jpeg",@"image/png",@"application/octet-stream",nil];
     manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    // 设置超时时间
        manager.requestSerializer.timeoutInterval = 15;
    
//    [manager POST:urlString parameters:<#(nullable id)#> progress:<#^(NSProgress * _Nonnull uploadProgress)uploadProgress#> success:<#^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject)success#> failure:<#^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)failure#>]
    
    
}

+(void)basePostRequestWithUrl:(NSString *)urlString parentDict:(NSDictionary *)dict successBlock:(httpBaseSuccessBlock)successBlock errorBlock:(httpBaseErrorBlock)errorBlock{
    
       AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
       manager.responseSerializer.acceptableContentTypes =  [NSSet setWithObjects:@"text/html",@"text/xml",@"text/json",@"text/plain",@"text/JavaScript",@"application/json",@"image/jpeg",@"image/png",@"application/octet-stream",nil];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
       
       // 设置超时时间
           manager.requestSerializer.timeoutInterval = 15;
       
    [manager POST:urlString parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        successBlock(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        errorBlock(error);
        
    }];
       
}


+(void)baseGetRequestWithUrl:(NSString *)urlString parentDict:(NSDictionary *)dict successBlock:(httpBaseSuccessBlock)successBlock errorBlock:(httpBaseErrorBlock)errorBlock{
    
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        
    AFHTTPRequestSerializer *requestSerializer =  [AFJSONRequestSerializer serializer];
    
      [requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",@"0451cc9a-ab96-47f1-9213-d0a76c835e2d"] forHTTPHeaderField:@"Authorization"];
    manager.requestSerializer = requestSerializer;
    
        manager.responseSerializer.acceptableContentTypes =  [NSSet setWithObjects:@"text/html",@"text/xml",@"text/json",@"text/plain",@"text/javascript",@"application/json",@"image/jpeg",@"image/png",@"application/octet-stream",@"charset=utf-8",nil];
         manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
  
        // 设置超时时间
            manager.requestSerializer.timeoutInterval = 30;
        
    
    [manager GET:urlString parameters:dict progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        /// 解析data数据
       NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        
        successBlock(dict);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        errorBlock(error);
    }];

}

@end
